#include <botan/otp.h>
#include <totp/totp.h>
namespace totp {
TOTP::TOTP(const QString &label, const Botan::SymmetricKey &key, const QString &algorithm, int digits, int period):
	label(label), key(key), algorithm(algorithm), digits(digits),  period(period) {}

std::string TOTP::generateOTP(std::string_view old_pass) {
	Botan::TOTP totpB(key, algorithm.toStdString(), digits, period);
	std::chrono::system_clock::time_point now  = std::chrono::system_clock::now();
	uint64_t unixTime = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
	auto res = std::to_string(totpB.generate_totp(unixTime));
	if(auto diff = digits-res.size(); diff != 0) {
		auto nullString = std::string(diff, '0');
		res = nullString + res;
	}
	if(res != old_pass)
		creation_time = now;
	return res;
}
}
